<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../../component/pear/css/pear.css" />
    <script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
</head>

<body>
    <form class="layui-form" action="">
        <div class="mainBox">
            <div class="main-container">
                <div class="main-container">
                    <input name="userId" hidden>
                    <div class="layui-form-item">
                        <label class="layui-form-label">金额</label>
                        <div class="layui-input-block">
                            <input type="text" name="amount" lay-verify="required" autocomplete="off"
                                placeholder="请输入金额" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="bottom">
            <div class="button-container">
                <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit=""
                    lay-filter="user-recharge">
                    <i class="layui-icon layui-icon-ok"></i>
                    充值
                </button>
            </div>
        </div>
    </form>
    <script src="../../component/layui/layui.js"></script>
    <script src="../../component/pear/pear.js"></script>
    <script>
        layui.use(['form', 'jquery'], function () {
            let form = layui.form;
            let $ = layui.jquery;

            form.on('submit(user-recharge)', function (data) {
                console.log(data.field.userId);
                console.log(data.field.amount);
                $.ajax({
                    url: '/api/wallet/addMoney?userId='+data.field.userId+'&amount='+data.field.amount,
                    contentType: 'application/json',
                    dataType: 'json',
                    type: 'post',
                    success: function (result) {
                        if (result.code == 200) {
                            layer.msg("充值成功", { icon: 1, time: 1000 }, function () {
                                parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                                parent.layui.table.reload('user-table');
                            });
                        } else {
                            layer.msg(result.msg, { icon: 2, time: 1000 });
                        }
                    }
                })
                return false;
            });
        })
    </script>
   
</body>

</html>